<?php
declare(strict_types=1);
//calluserfunc函数和call_user_func_array函数应用
Class c_func_calluserfunc extends Control
{
    public function index()
    {
        $data = ['a'=>1,'b'=>2];
        $data2 = ['c'=>3,'d'=>4];
        $class = new c_func_calluserfunc;
        $method = 'test';
        $res = call_user_func([$class, $method],$data);
        echo $res;
//        array
//        try {
//            $res = call_user_func_array([$class, 'test_array'],[$data,$data2]);
//            echo '<pre>';print_r($res);die;
//        }catch (Exception $e) {
//            echo $e->getMessage();
//        }
    }
    public function test($data)
    {
        return $data['a'] + $data['b'];
    }

    public function test_array($data1,$data2)
    {
        return $data1['a'] + $data1['b'] + $data2['c'] + $data2['d'];
    }
}